package com.jerry.errors;

import com.jerry.interfaces.IResponse;

import java.text.MessageFormat;

public class BusinessException extends RuntimeException implements IResponse {
    private final int code;

    private final String message;

    private final IResponse response;

    public BusinessException(IResponse response) {
        this("", response, null);
    }

    public BusinessException(String message, IResponse response) {
        this(message, response, null);
    }

    public BusinessException(String message, IResponse response, Object[] args) {
        super(message == null ? response.getMsg() : message);
        this.code = response.getCode();
        this.response = response;
        this.message = MessageFormat.format(response.getMsg(), args);
    }


    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return message;
    }
}
